package com.tech.connect.zhaofuwu;

import android.content.Intent;
import android.os.Bundle;
import android.widget.RadioGroup;

import com.tech.connect.R;
import com.tech.connect.activity.BaseActivity;

public class QuanZiActivity extends BaseActivity {

    private QuanZiImageFragment imageFragment;
    private QuanZiVideoFragment videoFragment;
    private QuanZiMineFragment mineFragment;
    private int index;

    @Override
    protected boolean isShowHeadBar() {
        return false;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_quanzi);
        Intent intent = getIntent();
        index = intent.getIntExtra("index", 0);
        initView();
        loadData();
    }

    private void initView() {
        RadioGroup rg = findViewById(R.id.rg);
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.rbImage) {
                    showFragment(0);
                } else if (checkedId == R.id.rbVideo) {
                    showFragment(1);
                } else if (checkedId == R.id.rbMine) {
                    showFragment(2);
                }
            }
        });
        if (index == 0) {
            rg.check(R.id.rbImage);
        } else if (index == 1) {
            rg.check(R.id.rbVideo);
        } else if (index == 2) {
            rg.check(R.id.rbMine);
        }
    }

    private void loadData() {

    }

    private void showFragment(int index) {
        if (index == 0) {
            if (imageFragment == null) {
                imageFragment = new QuanZiImageFragment();

                addFragment(R.id.container, imageFragment);
            }
            showFragment(imageFragment);
            hideFragment(videoFragment);
            hideFragment(mineFragment);

        } else if (index == 1) {
            if (videoFragment == null) {
                videoFragment = new QuanZiVideoFragment();
                addFragment(R.id.container, videoFragment);
            }
            hideFragment(imageFragment);
            showFragment(videoFragment);
            hideFragment(mineFragment);

        } else if (index == 2) {
            if (mineFragment == null) {
                mineFragment = new QuanZiMineFragment();
                addFragment(R.id.container, mineFragment);
            }
            hideFragment(imageFragment);
            hideFragment(videoFragment);
            showFragment(mineFragment);

        }
    }
}
